import { getJumpUrl } from "./util.js"
let storage = require('./storage.js')

let router = {
  push(obj){
    let result = getJumpUrl(obj)
		console.log(result,'result')
    if(!storage.get('userInfo').token){
      uni.redirectTo({
        url: `/pages/login/login?path=${encodeURIComponent(result['redirect']||result['url'])}`
      })
      return
    }
    uni.navigateTo({
      url: result['url'],
    })
  },
  replace(obj) {
    let result = getJumpUrl(obj)
    if(!storage.get('userInfo').token){
      uni.redirectTo({
        url: `/pages/login/login?path=${encodeURIComponent(result['redirect']||result['url'])}`
      })
      return
    }
    uni.redirectTo({
      url: result['url']
    })
  },
  reLaunch(obj) {
    let result = getJumpUrl(obj)
    if(!storage.get('userInfo').token){
      uni.redirectTo({
        url: `/pages/login/login?path=${encodeURIComponent(result['redirect']||result['url'])}`
      })
      return
    }
    uni.reLaunch({
      url: result['url']
    })
  },
  switchTab(obj) {
    let result = getJumpUrl(obj)
    if(!storage.get('userInfo').token){
      uni.redirectTo({
        url: `/pages/login/login?path=${encodeURIComponent(result['redirect']||result['url'])}`
      })
      return
    }
    uni.switchTab({
      url: result['url']
    })
  },
  back(delta = 1){
    uni.navigateBack({
      delta: delta
    })
  }
}
export default router